#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > choles_cc2_fop.info <<'%EOF%'
   choles_cc2_fop
   ----------------
   Molecule:         CO in C2v
   Wave Functions:   Cholesky CC2 / aug-cc-pVDZ
   Test Purpose:     First order properties
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > choles_cc2_fop.mol <<'%EOF%'
BASIS
aug-cc-pVDZ
CC2 unrelaxed FOP
test calculation
    2    2  X  Y  Z   1.00D-15
        6.0   1
C     0.0000000000000000  0.0000000000000000 1.21824313000000000       *
        8.0   1
O     0.0000000000000000  0.0000000000000000 -.91397310000000000       *

%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > choles_cc2_fop.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
.CHOLES
**INTEGRAL
.DIPLEN
.THETA
.EFGCAR
.SECMOM
.DARWIN
.MASSVELO
**CHOLES
.REDUCE
.SPANDI
  1.0d-3
.THRCOM
 1.0D-10
**WAVE FUNCTION
.CC
*SCF INP
.THRESH
 1.0D-8
.DOUBLY OCCUPIED
 5 1 1 0
*CC INP
.CC2
.PRINT
 1
.THRENR
1.0D-9
.THRLEQ
1.0D-08
*CCFOP
.NONREL
.ALLONE
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >choles_cc2_fop.check
cat >>choles_cc2_fop.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CC2 energies:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-112.75469112" | wc -l`
CRIT2=`$GREP "Coupled cluster MP2" $log | $GREP "\-113.05873920" | wc -l`
CRIT3=`$GREP "Total CC2   energy:                  -113.0657981" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=4
ERROR[1]="ENERGIES NOT CORRECT"


# Dipole moment
CRIT2=`$GREP "  z  " $log | $GREP "( -|-0)\.175911" | wc -l`
TEST[2]=$CRIT1
CTRL[2]=1
ERROR[2]="DIPOLE MOMENT NOT CORRECT"


# Quadrupole moment
CRIT1=`$GREP "( |0)\.80655...  * ( |0)\.00000000 *  ( |0)\.00000" $log | wc -l`
CRIT2=`$GREP "( |0)\.00000000  * ( |0)\.80655... *  ( |0)\.00000" $log | wc -l`
CRIT3=`$GREP "( |0)\.00000000  * ( |0)\.00000000 * \-1\.61310..." $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[3]=3
ERROR[3]="QUADRUPOLE MOMENT NOT CORRECT"


# Second moment of charge
CRIT1=`$GREP "7\.74658...  * ( |0)\.00000000 *  ( |0)\.00000" $log | wc -l`
CRIT2=`$GREP "( |0)\.00000000  * 7\.74658... *  ( |0)\.00000" $log | wc -l`
CRIT3=`$GREP "( |0)\.00000000  * ( |0)\.00000000 * 24.94716..." $log | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[4]=3
ERROR[4]="SECOND MOMENT NOT CORRECT"



# Relativistic correction
CRIT1=`$GREP "Darwin term" $log | $GREP "( |0)\.2604805" | wc -l`
CRIT1=`$GREP "Darwin term" $log | $GREP "( -|-0)\.0666929" | wc -l`
TEST[5]=`expr $CRIT1 \+ $CRIT2`
CTRL[5]=2
ERROR[5]="RELATIVISTIC CORRECTIONS NOT CORRECT"




PASSED=1
for i in 1 2 3 4 5
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi


%EOF%
chmod +x choles_cc2_fop.check
#######################################################################
